package com.hfkh;

/**
 * @Author MDD
 * @Description
 * @Version
 * @Date
 **/
public class StudentName {

    String[] names = {"tom","jery","san","meary",null};
    boolean flag = false;

    public boolean addName(String name){
        int index = -1;
        for (int i = 0; i < names.length; i++) {
            if (null==names[i]){
                names[i] = name;
                return true;
            }
        }
        return false;
    }


    public boolean editName(String oldName,String newName){

        for (int i = 0; i < names.length; i++) {
            if (names[i]!=null && names[i].equals(oldName)){
                names[i] = newName;
                return true;
            }
        }
        return false;
    }

    public boolean deleteName(String name){
        int index = -1;
        for (int i = 0; i < names.length; i++) {
            if (names[i]!=null&&names[i].equals(name)){
                /*names[i] = null;
                return true;*/
                index = i;
                break;
            }
        }
        if (index!=-1){
            for (int i = index; i <names.length-1 ; i++) {
                names[i] = names[i+1];
            }
            names[names.length-1]= null;
            return true;
        }
        return false;
    }

    public boolean find(int start,int end,String name){
        for (int i = start-1; i < end; i++) {
            if (names[i]!=null&&names[i].equals(name)){
                return true;
            }
        }
        return false;
    }

    public void print(){
        for (String name : names) {
            System.out.print(name+"\t");
        }
    }

}
